import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import VuexPersist from 'vuex-persist';
const vuexLocal = new VuexPersist({
  storage: window.sessionStorage,
})
export default new Vuex.Store({
  state: {
    users:{},
    goods:[],
  },
  mutations: {
    login(state,data){
        console.log('调用vuex中的数据');
        
          state.users = data;
        }
       
    },
    add(state,data){
      console.log('vuex中的数据',state);
      let index = state.users.findIndex((item)=>{
          
        return item._id = goods._id;
       })
       if (index > -1) {
           state.goods[index].num++;
       } else {
      state.goods.unshift(data);
       }
    },
    logout(state){
      state.users={}
    },
    checkAll(state,checked){
      console.log('全选',checked);
      state.goods.map(item=>{
         return  item.checked = checked
      })
    }
  },
  actions: {

  },
  plugins: [vuexLocal.plugin],
})
